/*
 * @Author: nccloud
 * @PageInfo: 复制
 */
import { ajax } from 'nc-lightapp-front';
import { STATUS } from '../../../../common/constant';
import { AREA, URL, FIELDS, UISTATUS } from '../../constance';
import { setCardPage } from '../utils/cardPageUtil';


export default function(props, pk) {
        pk = pk ? pk : props.form.getFormItemsValue(AREA.cardFormId, FIELDS.pk_head_fields).value;
        ajax({
                url: URL.copy,
                data: pk,
                success: (res) => {
                        if (res.success && res.data) {
                                props.setUrlParam({
                                        status: UISTATUS.copy,
                                        id: pk
                                });

                                setCardPage.call(this, props, res.data, false);

                                copyclear(props);
                        }
                }
        });
}

export function copyclear(props){
        props.form.setFormItemsValue(AREA.cardFormId, {
                [FIELDS.pk_head_fields]: { value: null, display: null },
                ['vbillcode']: { value: null, display: null },
                ['approver']: { value: null, display: null },
                ['approvestatus']: { value: STATUS.NOSTATE, display: '自由' },
                ['approvedate']: { value: null, display: null },
                ['modifier']: { value: null, display: null },
                ['modifiedtime']: { value: null, display: null },
                ['isflag']: { value: false, display: '否' },
                ['modifier']: { value: null, display: null },
                ['modifiedtime']: { value: null, display: null },
                ['lastmaketime']: { value: null, display: null },
                ['redno']: { value: null, display: null },
                ['hascount']: { value: null, display: null },
                ['nocount']: { value: null, display: null }
            });
            props.cardTable.setColValue(AREA.cardBody_1, 'pk_amortization_b', { value: null, display: null });
            props.cardTable.setColValue(AREA.cardBody_1, 'pk_amortization', { value: null, display: null });
            props.cardTable.setTableData(AREA.cardBody_2, {rows : []});
}
